//
//  VCOfThird.m
//  UI09_UITabBarController
//
//  Created by Scott on 16/5/13.
//  Copyright © 2016年 Scott. All rights reserved.
//

#import "VCOfThird.h"
#import "VCOfMessage.h"
#import "VCOfCall.h"

@interface VCOfThird ()

@property (nonatomic, retain) VCOfMessage *message;

@property (nonatomic, retain) VCOfCall *call;


@end

@implementation VCOfThird

- (void)dealloc {
    [_message release];
    [_call release];
    [super dealloc];
}

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        [self configTabBarItem];
        
    }
    return self;
}

- (void)childViewController {
    
    // message
    self.message = [[VCOfMessage alloc] init];
    self.message.view.frame = CGRectMake(0, 64, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds) - 64);
    
    [self addChildViewController:self.message];
    [self.view addSubview:self.message.view];
    
    // call
    self.call = [[VCOfCall alloc] init];
    self.call.view.frame = CGRectMake(0, 64, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds) - 64);
    
    [self addChildViewController:self.call];
    [self.view addSubview:self.call.view];
    
}
- (void)configNaviItem {
    
    UISegmentedControl *seg = [[UISegmentedControl alloc] initWithItems:@[@"消息", @"通话"]];
    
    seg.selectedSegmentIndex = 0;
    [self.view bringSubviewToFront:self.message.view];
    
    [seg addTarget:self action:@selector(handleSeg:) forControlEvents:UIControlEventValueChanged];
    
    
    self.navigationItem.titleView = seg;
    [seg release];
    
}

- (void)handleSeg:(UISegmentedControl *)seg {
    
    switch (seg.selectedSegmentIndex) {
        case 0:
            [self.view bringSubviewToFront:self.message.view];
            break;
          
        case 1:
            [self.view bringSubviewToFront:self.call.view];
            break;
            
        default:
            break;
    }

}

- (void)configTabBarItem {
    
    self.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"聊天" image:[UIImage imageNamed:@"liaotian"] tag:300];
    
    // 徽章设置.
    self.tabBarItem.badgeValue = @"99+";
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self childViewController];
    [self configNaviItem];
    
    
}



@end
